package o;

import android.text.Layout.Alignment;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.AlignmentSpan.Standard;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.text.style.UnderlineSpan;
import androidx.annotation.NonNull;
import com.google.android.exoplayer2.text.webvtt.WebvttCssStyle;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ReqAccessTokenParm;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import o.ako.a;

public final class akp {
    public static final Pattern ˊ = Pattern.compile("^(\\S+)\\s+-->\\s+(\\S+)(.*)?$");
    private static final Pattern ॱ = Pattern.compile("(\\S+?):(\\S+)");
    private final StringBuilder ˎ = new StringBuilder();

    static final class c {
        private static final String[] ॱ = new String[0];
        public final String ˊ;
        public final String ˋ;
        public final String[] ˎ;
        public final int ˏ;

        private c(String str, int i, String str2, String[] strArr) {
            this.ˏ = i;
            this.ˊ = str;
            this.ˋ = str2;
            this.ˎ = strArr;
        }

        public static c ˏ(String str, int i) {
            String trim = str.trim();
            if (trim.isEmpty()) {
                return null;
            }
            String str2;
            int indexOf = trim.indexOf(HwAccountConstants.BLANK);
            if (indexOf == -1) {
                str2 = trim;
                trim = "";
            } else {
                String trim2 = trim.substring(indexOf).trim();
                str2 = trim.substring(0, indexOf);
                trim = trim2;
            }
            String[] ˎ = anr.ˎ(str2, "\\.");
            String str3 = ˎ[0];
            if (ˎ.length > 1) {
                ˎ = (String[]) Arrays.copyOfRange(ˎ, 1, ˎ.length);
            } else {
                ˎ = ॱ;
            }
            return new c(str3, i, trim, ˎ);
        }

        public static c ˋ() {
            return new c("", 0, "", new String[0]);
        }
    }

    static final class d implements Comparable<d> {
        public final int ˋ;
        public final WebvttCssStyle ॱ;

        public /* synthetic */ int compareTo(@NonNull Object obj) {
            return ˎ((d) obj);
        }

        public d(int i, WebvttCssStyle webvttCssStyle) {
            this.ˋ = i;
            this.ॱ = webvttCssStyle;
        }

        public int ˎ(@NonNull d dVar) {
            return this.ˋ - dVar.ˋ;
        }
    }

    public boolean ॱ(anc o_anc, a aVar, List<WebvttCssStyle> list) {
        Object ˊˋ = o_anc.ˊˋ();
        if (ˊˋ == null) {
            return false;
        }
        Matcher matcher = ˊ.matcher(ˊˋ);
        if (matcher.matches()) {
            return ˏ(null, matcher, o_anc, aVar, this.ˎ, list);
        }
        CharSequence ˊˋ2 = o_anc.ˊˋ();
        if (ˊˋ2 == null) {
            return false;
        }
        matcher = ˊ.matcher(ˊˋ2);
        if (!matcher.matches()) {
            return false;
        }
        return ˏ(ˊˋ.trim(), matcher, o_anc, aVar, this.ˎ, list);
    }

    static void ॱ(String str, a aVar) {
        Matcher matcher = ॱ.matcher(str);
        while (matcher.find()) {
            String group = matcher.group(1);
            String group2 = matcher.group(2);
            try {
                if ("line".equals(group)) {
                    ˏ(group2, aVar);
                } else if ("align".equals(group)) {
                    aVar.ˎ(ॱ(group2));
                } else if ("position".equals(group)) {
                    ˎ(group2, aVar);
                } else if ("size".equals(group)) {
                    aVar.ˎ(akq.ˏ(group2));
                } else {
                    amz.ˏ("WebvttCueParser", "Unknown cue setting " + group + ":" + group2);
                }
            } catch (NumberFormatException e) {
                amz.ˏ("WebvttCueParser", "Skipping bad cue setting: " + matcher.group());
            }
        }
    }

    static void ˋ(String str, String str2, a aVar, List<WebvttCssStyle> list) {
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        ArrayDeque arrayDeque = new ArrayDeque();
        List arrayList = new ArrayList();
        int i = 0;
        while (i < str2.length()) {
            char charAt = str2.charAt(i);
            int indexOf;
            switch (charAt) {
                case '&':
                    indexOf = str2.indexOf(59, i + 1);
                    int indexOf2 = str2.indexOf(32, i + 1);
                    if (indexOf == -1) {
                        indexOf = indexOf2;
                    } else if (indexOf2 != -1) {
                        indexOf = Math.min(indexOf, indexOf2);
                    }
                    if (indexOf == -1) {
                        spannableStringBuilder.append(charAt);
                        i++;
                        break;
                    }
                    ˋ(str2.substring(i + 1, indexOf), spannableStringBuilder);
                    if (indexOf == indexOf2) {
                        spannableStringBuilder.append(HwAccountConstants.BLANK);
                    }
                    i = indexOf + 1;
                    break;
                case o.fc.c.ᴵ /*60*/:
                    if (i + 1 < str2.length()) {
                        Object obj = str2.charAt(i + 1) == '/' ? 1 : null;
                        indexOf = ॱ(str2, i + 1);
                        Object obj2 = str2.charAt(indexOf + -2) == '/' ? 1 : null;
                        String substring = str2.substring((obj != null ? 2 : 1) + i, obj2 != null ? indexOf - 2 : indexOf - 1);
                        String ˊ = ˊ(substring);
                        if (ˊ != null) {
                            if (ˎ(ˊ)) {
                                if (obj == null) {
                                    if (obj2 == null) {
                                        arrayDeque.push(c.ˏ(substring, spannableStringBuilder.length()));
                                        i = indexOf;
                                        break;
                                    }
                                }
                                while (!arrayDeque.isEmpty()) {
                                    c cVar = (c) arrayDeque.pop();
                                    ˏ(str, cVar, spannableStringBuilder, list, arrayList);
                                    if (cVar.ˊ.equals(ˊ)) {
                                        i = indexOf;
                                        break;
                                    }
                                }
                                i = indexOf;
                            } else {
                                i = indexOf;
                                break;
                            }
                        }
                        i = indexOf;
                        break;
                    }
                    i++;
                    break;
                default:
                    spannableStringBuilder.append(charAt);
                    i++;
                    break;
            }
        }
        while (!arrayDeque.isEmpty()) {
            ˏ(str, (c) arrayDeque.pop(), spannableStringBuilder, list, arrayList);
        }
        ˏ(str, c.ˋ(), spannableStringBuilder, list, arrayList);
        aVar.ˋ(spannableStringBuilder);
    }

    private static boolean ˏ(String str, Matcher matcher, anc o_anc, a aVar, StringBuilder stringBuilder, List<WebvttCssStyle> list) {
        try {
            aVar.ˋ(akq.ॱ(matcher.group(1))).ˎ(akq.ॱ(matcher.group(2)));
            ॱ(matcher.group(3), aVar);
            stringBuilder.setLength(0);
            while (true) {
                Object ˊˋ = o_anc.ˊˋ();
                if (TextUtils.isEmpty(ˊˋ)) {
                    ˋ(str, stringBuilder.toString(), aVar, (List) list);
                    return true;
                }
                if (stringBuilder.length() > 0) {
                    stringBuilder.append("\n");
                }
                stringBuilder.append(ˊˋ.trim());
            }
        } catch (NumberFormatException e) {
            amz.ˏ("WebvttCueParser", "Skipping cue with bad header: " + matcher.group());
            return false;
        }
    }

    private static void ˏ(String str, a aVar) throws NumberFormatException {
        int indexOf = str.indexOf(44);
        if (indexOf != -1) {
            aVar.ˋ(ˏ(str.substring(indexOf + 1)));
            str = str.substring(0, indexOf);
        } else {
            aVar.ˋ(Integer.MIN_VALUE);
        }
        if (str.endsWith("%")) {
            aVar.ˋ(akq.ˏ(str)).ˏ(0);
            return;
        }
        indexOf = Integer.parseInt(str);
        if (indexOf < 0) {
            indexOf--;
        }
        aVar.ˋ((float) indexOf).ˏ(1);
    }

    private static void ˎ(String str, a aVar) throws NumberFormatException {
        int indexOf = str.indexOf(44);
        if (indexOf != -1) {
            aVar.ˎ(ˏ(str.substring(indexOf + 1)));
            str = str.substring(0, indexOf);
        } else {
            aVar.ˎ(Integer.MIN_VALUE);
        }
        aVar.ॱ(akq.ˏ(str));
    }

    private static int ˏ(String str) {
        int i = -1;
        switch (str.hashCode()) {
            case -1364013995:
                if (str.equals("center")) {
                    i = 1;
                    break;
                }
                break;
            case -1074341483:
                if (str.equals("middle")) {
                    i = 2;
                    break;
                }
                break;
            case 100571:
                if (str.equals("end")) {
                    i = 3;
                    break;
                }
                break;
            case 109757538:
                if (str.equals("start")) {
                    i = 0;
                    break;
                }
                break;
        }
        switch (i) {
            case 0:
                return 0;
            case 1:
            case 2:
                return 1;
            case 3:
                return 2;
            default:
                amz.ˏ("WebvttCueParser", "Invalid anchor value: " + str);
                return Integer.MIN_VALUE;
        }
    }

    private static Alignment ॱ(String str) {
        Object obj = -1;
        switch (str.hashCode()) {
            case -1364013995:
                if (str.equals("center")) {
                    obj = 2;
                    break;
                }
                break;
            case -1074341483:
                if (str.equals("middle")) {
                    obj = 3;
                    break;
                }
                break;
            case 100571:
                if (str.equals("end")) {
                    obj = 4;
                    break;
                }
                break;
            case 3317767:
                if (str.equals("left")) {
                    obj = 1;
                    break;
                }
                break;
            case 108511772:
                if (str.equals("right")) {
                    obj = 5;
                    break;
                }
                break;
            case 109757538:
                if (str.equals("start")) {
                    obj = null;
                    break;
                }
                break;
        }
        switch (obj) {
            case null:
            case 1:
                return Alignment.ALIGN_NORMAL;
            case 2:
            case 3:
                return Alignment.ALIGN_CENTER;
            case 4:
            case 5:
                return Alignment.ALIGN_OPPOSITE;
            default:
                amz.ˏ("WebvttCueParser", "Invalid alignment value: " + str);
                return null;
        }
    }

    private static int ॱ(String str, int i) {
        int indexOf = str.indexOf(62, i);
        return indexOf == -1 ? str.length() : indexOf + 1;
    }

    private static void ˋ(String str, SpannableStringBuilder spannableStringBuilder) {
        Object obj = -1;
        switch (str.hashCode()) {
            case 3309:
                if (str.equals("gt")) {
                    obj = 1;
                    break;
                }
                break;
            case 3464:
                if (str.equals("lt")) {
                    obj = null;
                    break;
                }
                break;
            case 96708:
                if (str.equals("amp")) {
                    obj = 3;
                    break;
                }
                break;
            case 3374865:
                if (str.equals("nbsp")) {
                    obj = 2;
                    break;
                }
                break;
        }
        switch (obj) {
            case null:
                spannableStringBuilder.append('<');
                return;
            case 1:
                spannableStringBuilder.append('>');
                return;
            case 2:
                spannableStringBuilder.append(' ');
                return;
            case 3:
                spannableStringBuilder.append('&');
                return;
            default:
                amz.ˏ("WebvttCueParser", "ignoring unsupported entity: '&" + str + ";'");
                return;
        }
    }

    private static boolean ˎ(String str) {
        boolean z = true;
        switch (str.hashCode()) {
            case 98:
                if (str.equals("b")) {
                    z = false;
                    break;
                }
                break;
            case 99:
                if (str.equals("c")) {
                    z = true;
                    break;
                }
                break;
            case 105:
                if (str.equals("i")) {
                    z = true;
                    break;
                }
                break;
            case 117:
                if (str.equals("u")) {
                    z = true;
                    break;
                }
                break;
            case 118:
                if (str.equals("v")) {
                    z = true;
                    break;
                }
                break;
            case 3314158:
                if (str.equals(ReqAccessTokenParm.LANGUAGE_LABEL)) {
                    z = true;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
            case true:
            case true:
            case true:
            case true:
            case true:
                return true;
            default:
                return false;
        }
    }

    private static void ˏ(String str, c cVar, SpannableStringBuilder spannableStringBuilder, List<WebvttCssStyle> list, List<d> list2) {
        int i = cVar.ˏ;
        int length = spannableStringBuilder.length();
        String str2 = cVar.ˊ;
        int i2 = -1;
        switch (str2.hashCode()) {
            case 0:
                if (str2.equals("")) {
                    i2 = 6;
                    break;
                }
                break;
            case 98:
                if (str2.equals("b")) {
                    i2 = 0;
                    break;
                }
                break;
            case 99:
                if (str2.equals("c")) {
                    i2 = 3;
                    break;
                }
                break;
            case 105:
                if (str2.equals("i")) {
                    i2 = 1;
                    break;
                }
                break;
            case 117:
                if (str2.equals("u")) {
                    i2 = 2;
                    break;
                }
                break;
            case 118:
                if (str2.equals("v")) {
                    i2 = 5;
                    break;
                }
                break;
            case 3314158:
                if (str2.equals(ReqAccessTokenParm.LANGUAGE_LABEL)) {
                    i2 = 4;
                    break;
                }
                break;
        }
        switch (i2) {
            case 0:
                spannableStringBuilder.setSpan(new StyleSpan(1), i, length, 33);
                break;
            case 1:
                spannableStringBuilder.setSpan(new StyleSpan(2), i, length, 33);
                break;
            case 2:
                spannableStringBuilder.setSpan(new UnderlineSpan(), i, length, 33);
                break;
            case 3:
            case 4:
            case 5:
            case 6:
                break;
            default:
                return;
        }
        list2.clear();
        ˏ(list, str, cVar, list2);
        int size = list2.size();
        for (i2 = 0; i2 < size; i2++) {
            ˋ(spannableStringBuilder, ((d) list2.get(i2)).ॱ, i, length);
        }
    }

    private static void ˋ(SpannableStringBuilder spannableStringBuilder, WebvttCssStyle webvttCssStyle, int i, int i2) {
        if (webvttCssStyle != null) {
            if (webvttCssStyle.ॱ() != -1) {
                spannableStringBuilder.setSpan(new StyleSpan(webvttCssStyle.ॱ()), i, i2, 33);
            }
            if (webvttCssStyle.ˊ()) {
                spannableStringBuilder.setSpan(new StrikethroughSpan(), i, i2, 33);
            }
            if (webvttCssStyle.ˎ()) {
                spannableStringBuilder.setSpan(new UnderlineSpan(), i, i2, 33);
            }
            if (webvttCssStyle.ʽ()) {
                spannableStringBuilder.setSpan(new ForegroundColorSpan(webvttCssStyle.ॱॱ()), i, i2, 33);
            }
            if (webvttCssStyle.ʼ()) {
                spannableStringBuilder.setSpan(new BackgroundColorSpan(webvttCssStyle.ᐝ()), i, i2, 33);
            }
            if (webvttCssStyle.ˋ() != null) {
                spannableStringBuilder.setSpan(new TypefaceSpan(webvttCssStyle.ˋ()), i, i2, 33);
            }
            if (webvttCssStyle.ʻ() != null) {
                spannableStringBuilder.setSpan(new Standard(webvttCssStyle.ʻ()), i, i2, 33);
            }
            switch (webvttCssStyle.ͺ()) {
                case 1:
                    spannableStringBuilder.setSpan(new AbsoluteSizeSpan((int) webvttCssStyle.ˊॱ(), true), i, i2, 33);
                    return;
                case 2:
                    spannableStringBuilder.setSpan(new RelativeSizeSpan(webvttCssStyle.ˊॱ()), i, i2, 33);
                    return;
                case 3:
                    spannableStringBuilder.setSpan(new RelativeSizeSpan(webvttCssStyle.ˊॱ() / 100.0f), i, i2, 33);
                    return;
                default:
                    return;
            }
        }
    }

    private static String ˊ(String str) {
        String trim = str.trim();
        if (trim.isEmpty()) {
            return null;
        }
        return anr.ˊ(trim, "[ \\.]")[0];
    }

    private static void ˏ(List<WebvttCssStyle> list, String str, c cVar, List<d> list2) {
        int size = list.size();
        for (int i = 0; i < size; i++) {
            WebvttCssStyle webvttCssStyle = (WebvttCssStyle) list.get(i);
            int ˏ = webvttCssStyle.ˏ(str, cVar.ˊ, cVar.ˎ, cVar.ˋ);
            if (ˏ > 0) {
                list2.add(new d(ˏ, webvttCssStyle));
            }
        }
        Collections.sort(list2);
    }
}
